<template>
  <div class="app-container">
    <el-row  style="min-width: 300px">
      <el-col  >
        <div class="grid-content bg-purple">
          <el-card class="box-card">
            <div slot="header" class="clearfix">
              <span>个人中心</span>
            </div>
            <div class="name-role">
            </div>

            <div class="registe-info">
              <div class="block">
                <el-avatar shape="square" :size="100" :src="userInfo.userAvatar"></el-avatar>
              </div>
              <span class="registe-info">昵称： {{userInfo.userNickname}}
              </span>
            </div>
            <el-divider></el-divider>
            <div class="personal-relation">
              <div class="relation-item">手机号:  <div style="float: right; padding-right:20px;">{{userInfo.userPhone}}</div></div>
            </div>
            <div class="personal-relation">
              <div class="relation-item">邮箱： <div style="float: right; padding-right:20px;">{{userInfo.userEmail}}</div></div>
            </div>
            <div class="personal-relation">
              <div class="relation-item">skill：
                <div style="float: right; padding-right:20px;">
                  <el-tag v-for="item in userInfo.userSkill" :key="item.index">{{item}}

                  </el-tag>
                </div>
              </div>
            </div>
          </el-card>
        </div>
      </el-col>
      <el-col>
        <div class="grid-content bg-purple" style="margin-top:5px">
          <el-card class="box-card">
            <div slot="header" class="clearfix">
              <span>密码修改</span>
            </div>
            <div>
              <el-form label-width="100px" v-model="userInfo" size="small" label-position="right">
                <el-form-item label="原密码" prop="nickName">
                  <el-input  auto-complete="off" v-model="userInfo.nickName"></el-input>
                </el-form-item>
                <el-form-item label="请输入新密码" prop="phone">
                  <el-input auto-complete="off" v-model="userInfo.phone"></el-input>
                </el-form-item>
                <el-form-item label="请确认新密码" prop="homeUrl">
                  <el-input  maxlength="18" v-model="userInfo.homeUrl"></el-input>
                </el-form-item>
              </el-form>
              <div slot="footer" class="dialog-footer">
                <el-button type="primary">提交</el-button>
              </div>
            </div>

          </el-card>
        </div>
      </el-col>
    </el-row>


    <el-row style="margin: 5px; min-width: 500px">
        <div class="grid-content bg-purple">
          <el-card class="box-card">
            <div slot="header" class="clearfix">
              <span>基本资料</span>
            </div>
            <div>
              <el-form label-width="80px" v-model="userInfo" size="small" label-position="right">
                <el-form-item label="更换头像" prop="avatar">
                  <upload-avatar @refresh-me="updateAvatarUrl" :userId="userInfo.userId"></upload-avatar>
                </el-form-item>
                <el-form-item label="用户名" prop="userName">
                  <el-input  auto-complete="off" v-model="userInfo.userLoginName"></el-input>
                </el-form-item>
                <el-form-item label="用户昵称" prop="nickName">
                  <el-input  auto-complete="off" v-model="userInfo.userNickname"></el-input>
                </el-form-item>
                <el-form-item label="手机号" prop="phone">
                  <el-input auto-complete="off" v-model="userInfo.userPhone"></el-input>
                </el-form-item>
                <el-form-item label="用户邮箱" prop="nickName">
                  <el-input  auto-complete="off" v-model="userInfo.userEmail"></el-input>
                </el-form-item>
                <el-form-item label="用户技能" >

                  <skill-tags @refresh-skill="changeSkillTags" :userId="userInfo.userId" ></skill-tags>

                </el-form-item>
                <el-form-item label="用户状态" prop="nickName">
                  {{userInfo.userStatus}}
                </el-form-item>
              </el-form>
              <div slot="footer" class="dialog-footer">
                <el-button type="primary" v-on:click="submitUpdate">提交</el-button>
              </div>
            </div>

          </el-card>

        </div>
    </el-row>

    <el-row :gutter="0" style="margin-top:5px;">
      <el-timeline>
        <el-timeline-item timestamp="2018/4/12" placement="top">
          <el-card>
            <h4>更新 Github 模板</h4>
            <p>王小虎 提交于 2018/4/12 20:46</p>
          </el-card>
        </el-timeline-item>
        <el-timeline-item timestamp="2018/4/3" placement="top">
          <el-card>
            <h4>更新 Github 模板</h4>
            <p>王小虎 提交于 2018/4/3 20:46</p>
          </el-card>
        </el-timeline-item>
        <el-timeline-item timestamp="2018/4/2" placement="top">
          <el-card>
            <h4>更新 Github 模板</h4>
            <p>王小虎 提交于 2018/4/2 20:46</p>
          </el-card>
        </el-timeline-item>
      </el-timeline>
    </el-row>

  </div>
</template>

<script>


import {userGet} from "@/api/user";
import uploadAvatar from "@/views/user/uploadAvatar";
// import skillTag from "@/views/user/skillTag";

export default {
  name: 'userInfo',
  components: {uploadAvatar},
  created() {
    this.getMyInformation()
  },
  data() {
    return {
      inputVisible: false,
      inputValue: '',
      userInfo:{
        userId: '1',
        userLoginName: '',
        userNickname: '',
        userEmail: '',
        userPhone: '',
        userAvatar: '',
        userPassword: '',
        userStatus: '',
        userLoginIp: '',
        userLoginDate: '',
        userPwdUpdateDate: '',
        userInfoUpdateTime: '',
        userSkill: []
      }
    }
  },
  methods:{
    getMyInformation(){
      userGet(this.userInfo.userId).then(res => {
        this.userInfo = res.data
        this.userInfo.userSkill = JSON.parse(res.data.userSkill)
      })
    },
    updateAvatarUrl(para){
      this.userInfo.userAvatar = para;
    },
    submitUpdate(){
      // 上传，将数组变为字符串上传
      let params = {
        userId : this.userInfo.userId,
        userLoginName: this.userInfo.userLoginName,
        userNickname: this.userInfo.userNickname,
        userEmail: this.userInfo.userEmail,
        userPhone: this.userInfo.userPhone,
        userAvatar: this.userInfo.userAvatar,
        userStatus: this.userInfo.userStatus,
        userSkill: JSON.stringify(this.userInfo.userSkill)
      };
      userSave(params).then(
        res => {
          if (res.code===0) {
            this.$message({
              type: 'success',
              message: '保存成功'
            })

          } else {
            this.$message({
              /*上传失败*/
              type: 'error',
              message: res.msg
            })
          }
        }
      )
    },
    changeSkillTags(para) {
      this.userInfo.userSkill = para;
    }
  }
}
</script>

<style scoped>

.text {
  font-size: 14px;
}

.item {
  margin-bottom: 18px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both
}

.box-card {
  width: 100%;
}
.sender{
  text-align:center;
}
.registe-info{
  text-align: center;
  padding-top:10px;
}
.personal-relation {
  font-size: 16px;
  padding: 0px 5px 15px;
  margin-right: 1px;
  width: 100%
}

.relation-item {
  padding: 12px;

}
.dialog-footer{
  padding-top:10px ;
  padding-left: 10%;
}

.el-col {
  border-radius: 4px;
}
.bg-purple-dark {
  background: #99a9bf;
}
.bg-purple {
  background: #d3dce6;
}
.bg-purple-light {
  background: #e5e9f2;
}
.grid-content {
  border-radius: 4px;
  min-height: 36px;
}
.row-bg {
  padding: 10px 0;
  background-color: #f9fafc;
}

.app-container{
  margin: 50px;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
}
</style>
